<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:include="inc/home::header">
</head>
<link type="text/css" th:href="@{/css/content.css}" rel="stylesheet" />
<body>
	<!--返回-->
	<div class="back" onclick="loadPage('/plan')">
		<img src="images/back.png" alt="" />
	</div>
	<div class="head-top">
		<div th:include="header :: header"></div>
	</div>
	<div class="header-title">
		<span th:text="${title}">添加</span>
	</div>
	<div class="spare-a">
		<div class="save-bg">
			<a href="#" class="spare-tj" onclick="Save()">保 存</a>
		</div>

		<div class="spare-add">
			<form id="planTypeForm" action="">
				<input type="text" readonly="readonly" style="display: none"
					name="id" /> <input type="text" readonly="readonly"
					style="display: none" name="userName" />
				<ul>
					<!--     <li>
						<div class="spare-addl">所属模块：</div>
						<div class="spare-addr">
							<select class="spare-add-select">
								<option>计划类</option>
								<option>考试类</option>
							</select>
							<div class="select-arrow"></div>
						</div>
					</li> -->

					<li>
						<div class="spare-addl">指派给：</div>
						<div class="spare-addr">
							<select class="spare-add-select" name="userId" id="userId">
								<option>请选择</option>

							</select>
							<div class="select-arrow"></div>
						</div>
					</li>
					<li>
						<div class="spare-addl">任务名称：</div>
						<div class="spare-addr">
							<input type="text" class="spare-add-input" name="name" />
						</div>
					</li>
					<li>
						<div class="spare-addl">任务描述：</div>
						<div class="spare-addr">
							<textarea class="spare-add-textarea" name="taskDescription"
								cols="" rows=""></textarea>
						</div>
					</li>
					<li>
						<div class="spare-addl">预计开始：</div>
						<div class="spare-addr">
							<input type="text" class="spare-add-input" onclick="laydate()"
								name="planStar" id="planStar"/>
						</div>
					</li>
					<li>
						<div class="spare-addl">截止日期：</div>
						<div class="spare-addr">
							<input type="text" class="spare-add-input" onclick="laydate()"
								name="planNode"  id="planNode" />
						</div>
					</li>

				</ul>
			</form>
		</div>

	</div>
</body>
<script th:inline="javascript" type="text/javascript">  
/*<![CDATA[*/  
	function verifyNull(obj){
	
		if(obj == null||obj.val()==""||obj.val()=="请选择"){
			top.$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">输入的内容不能包含空</div></div>', {
				'title':'提示',
	 	         'buttons':['确定']
		     });
			return false;
		}
	return true;
}      
 function getData(){
	if(!verifyNull($("#taskDescription"))){
 		return false;
 	}
	if(!verifyNull($("#planNode"))){
 		return false;
 	}
	if(!verifyNull($("#palnTypeId"))){
 		return false;
 	}
	if(!verifyNull($("#userId"))){
 		return false;
 	}
	return true;
 }
        
 
 function Save(){
		var validate=getData();
		  if(!validate){
			 return false;
		 }
		  
		  var s=$("#planStar").val();
		  var e=$("#planNode").val();

		    var startTimeArray =s.split("-");
	        var endTimeArray = e.split("-");
	        var startDate = new Date(startTimeArray[0],startTimeArray[1],startTimeArray[2]);
	        var endDate = new Date(endTimeArray[0],endTimeArray[1],endTimeArray[2]);
	        var start = startDate.getTime();
	        var end = endDate.getTime();
		 
		 if(start > end){

				$.Zebra_Dialog(
						'<div class="prompt"><div class="success-icon"></div><div class="success-title">开始时间大于结束时间,请重新设置</div></div>',
						{
							'title' : '提示',
							'show_close_button' : false,
							'buttons' : [ {
								caption : '确定',
								callback : function() {
									
								}
							} ]
						});
				
				return
			 
			 
			 
			 
		 }
	
	   var data= getDataJson("planTypeForm");
	   var obj = JSON.stringify(data);
      AjaxWebTableInfo("/Plan/saveOrUpdate",data);
	 }
	      
	function AjaxWebTableInfo(url , obj){
		 $.ajax({
		     type: "post",
		     dataType: "json",
		     url: url,
		     data:obj,
		     success: function (data, status) {
		    	 if(data.code==500){
		    			$.Zebra_Dialog(
								'<div class="prompt"><div class="success-icon"></div><div class="success-title">存在此条记录</div></div>',
								{
									'title' : '提示',
									'show_close_button' : false,
									'buttons' : [ {
										caption : '确定',
										callback : function() {
											loadPage("/plan");
										}
									} ]
								});
		    	 }else{
		    			$.Zebra_Dialog(
								'<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功</div></div>',
								{
									'title' : '提示',
									'show_close_button' : false,
									'buttons' : [ {
										caption : '确定',
										callback : function() {
											loadPage("/plan");
										}
									} ]
								});
		    	 }
		    	 	
		     },
		     error: function (data) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">保存失败!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		     }
		 });	
	}

	//加载用户
	$(function() { 
	$.ajax({
	    type: 'post',
	    url: '/User/users?timestamp='+new Date().getTime(),
	    success: function (data) {
	        var data = eval(data);
	        var proOPts = "";
	        $.each(data, function (i) {
	           	if(data[i].userName!="sa"){
	           	  proOPts += "<option value='" + data[i].id+ "'>" + data[i].userName + "</option>";
	        	}
	          
	        });
	        $("#userId").append(proOPts);
	         var plan = [[${plan}]];  
	         if(plan!=null){
	            loadData(plan);
	         }
	    }
	}); 

	}); 
/*]]>*/  
</script>

<script type="text/javascript">  
$(function() { 
$('#userId').change(function(){  
$("input[name='userName']").val($(this).children('option:selected').text());
}); 
});
</script>
</html>
